<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>部门管理</title>
<link th:href="@{/css/style.css}" rel="stylesheet" type="text/css" />
<script type="text/javascript" th:src="@{/js/jquery.js}"></script>
<script type="text/javascript">
  function tipOpen(ele) {
    $(".tipright p").text("您确定要修改此部门吗?");
    $("#tip").fadeIn(200);
    var did = $(ele).prev().val();
    $("#did2").val(did);
  }
function tipClose() {
	$("#tip").fadeOut(200);
}
function yes() {
  $("#tip").fadeOut(200);
  var did = $("#did2").val();
  window.location.href="/erp/sys/dept/updateStatus?id="+did;
}
</script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>系统管理</li>
    <li>部门管理</li>
  </ul>
</div>
<div class="rightinfo">
  <form id="deptForm" th:action="@{/sys/dept/findByPage}" method="post">
    <input type="hidden" name="pageno" id="pageno"/>
    <ul class="tools">
      <li> <label>部门名称:</label>
        <input id="deptName" th:value="${dept==null?'':dept.deptName}" name="deptName"  type="text" />
      </li>
      <li> 所属区域：
        <select name="pId">
          <option value="0">请选择省份</option>
          <option th:each="p:${session.plist}" th:value="${p.id}" th:text="${p.pName}"
          th:selected="${p.id==dept.pId?'true':'false'}">北京</option>
        </select>
        <select name="cId">
          <option value="0">请选择城市</option>
          <option th:each="c:${clist}" th:value="${c.id}" th:text="${c.cName}"
                  th:selected="${c.id==dept.cId?'true':'false'}">北京</option>
        </select>
      </li>
      <li class="subBut" onclick="Search(1)"><img th:src="@{/images/t06.png}" />查询</li>
      <li class="subBut" onclick="window.location.href='/erp/sys/dept/deptAdd.html'"><img th:src="@{/images/t01.png}" />添加</li>
    </ul>
    <table class="tablelist">
      <thead>
        <tr>
          <th>序号</th>
          <th>部门编号</th>
          <th>部门名称</th>
          <th>所属地区</th>
          <th>状态</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <tr th:each="d,var:${pageInfo.list}">
          <td th:text="${(pageInfo.pageNum-1)*pageInfo.pageSize+var.count}"></td>
          <td th:text="${d.deptId}">001</td>
          <td th:text="${d.deptName}">研发部</td>
          <td th:text="${d.province.pName+d.city.cName}">深圳</td>
          <td th:text="${d.deptState=='1'?'启用':'禁用'}">正常</td>
          <td>
            <a th:if="${session.users.jobId==1||(session.users.jobId==9&&d.deptId!=5)}" th:href="@{'/sys/dept/goUpdate?id='+${d.deptId}}" class="tablelink">修改</a>
            <input type="hidden" th:value="${d.deptId}" />
            <a href="javascript:void(0)" th:if="${session.users.jobId==1||(session.users.jobId==9&&d.deptId!=5)}" th:text="${d.deptState.equals('1')?'注销':'恢复'}" class="tablelink" onclick="tipOpen(this)">注销</a>
          </td>
        </tr>
      </tbody>
    </table>
    <div class="pagin">
      <div class="message">共<i class="blue" th:text="${pageInfo.total}">1256</i>条记录，当前显示第&nbsp;<i class="blue" th:text="${pageInfo.pageNum}">2&nbsp;</i>页</div>
      <ul class="paginList">
        <li class="paginItem">
          <a href="javascript:void(0);" th:onclick="Search([[${pageInfo.isFirstPage?1:pageInfo.pageNum-1}]])">
            <span th:class="${pageInfo.isFirstPage?'pagepre':'pagenxt roate'}"></span>
          </a>
        </li>
        <li class="paginItem" th:if="${1+4<=pageInfo.pageNum}">
          <a th:onclick="Search(1)" href="javascript:void(0);">1</a>
        </li>
        <li class="paginItem more" th:if="${1+5<=pageInfo.pageNum}">
          <a href="javascript:void(0);">...</a>
        </li>
        <li class="paginItem" th:if="${1+3<=pageInfo.pageNum}">
          <a th:onclick="Search([[${pageInfo.pageNum-3}]])" href="javascript:void(0);" th:text="${pageInfo.pageNum-3}">3</a>
        </li>
        <li class="paginItem" th:if="${1+2<=pageInfo.pageNum}">
          <a th:onclick="Search([[${pageInfo.pageNum-2}]])" href="javascript:void(0);" th:text="${pageInfo.pageNum-2}">4</a>
        </li>
        <li class="paginItem" th:if="${1+1<=pageInfo.pageNum}">
          <a th:onclick="Search([[${pageInfo.pageNum-1}]])" href="javascript:void(0);" th:text="${pageInfo.pageNum-1}">1</a>
        </li>
        <li class="paginItem current">
          <a href="javascript:void(0);" th:text="${pageInfo.pageNum}">2</a>
        </li>
        <li class="paginItem" th:if="${pageInfo.pages-1>=pageInfo.pageNum}">
          <a th:onclick="Search([[${pageInfo.pageNum+1}]])" href="javascript:void(0);" th:text="${pageInfo.pageNum+1}">3</a>
        </li>
        <li class="paginItem" th:if="${pageInfo.pages-2>=pageInfo.pageNum}">
          <a th:onclick="Search([[${pageInfo.pageNum+2}]])" href="javascript:void(0);" th:text="${pageInfo.pageNum+2}">4</a>
        </li>
        <li class="paginItem" th:if="${pageInfo.pages-3>=pageInfo.pageNum}">
          <a th:onclick="Search([[${pageInfo.pageNum+3}]])" href="javascript:void(0);" th:text="${pageInfo.pageNum+3}">5</a>
        </li>
        <li class="paginItem more" th:if="${pageInfo.pages-5>=pageInfo.pageNum}">
          <a href="javascript:void(0);">...</a>
        </li>
        <li class="paginItem" th:if="${pageInfo.pages-4>=pageInfo.pageNum}">
          <a th:onclick="Search([[${pageInfo.pages}]])" href="javascript:void(0);" th:text="${pageInfo.pages}">10</a>
        </li>
        <li class="paginItem">
          <a href="javascript:void(0);" th:onclick="Search([[${pageInfo.isLastPage?pageInfo.pages:pageInfo.pageNum+1}]])">
            <span th:class="${pageInfo.isLastPage?'pagepre roate ':'pagenxt '}"></span>
          </a>
        </li>
      </ul>
    </div>
  </form>

  <script>
    function Search(pageNum) {
      $("#pageno").val(pageNum);
      $("#deptForm").submit();
    }
  </script>

  <script>
    $(function () {
      ajaxCid($("select[name=pId]").val());

      $("select[name=pId]").change(function () {
        ajaxCid($(this).val());
      });
    });
    //域内容发生变化的事件
    function ajaxCid(pid) {
      $.ajax({
        url: "/erp/market/customer/ajaxCityPid",
        data: {"pid": pid},
        dataType: "JSON",
        success: function (data) {
          var city = JSON.parse(data);
          var op = "<option value='0'>请选择城市</option>";
          $.each(city, function (i, e) {
            if (e.id == $("input[name=cid]").val()) {
              op += "<option value='" + e.id + "' selected>" + e.cname + "</option>";
            } else {
              op += "<option value='" + e.id + "'>" + e.cname + "</option>";
            }
          });
          $("select[name=cId]").html("");
          $("select[name=cId]").append(op);

        }, error: function () {
          console.log("错误");
        }
      });
    }
  </script>

  <!-- 提示框 -->
  <div id="tip" class="tip">
    <div class="tiptop"><span>提示信息</span><a onclick="tipClose()"></a></div>
    <div class="tipinfo"> <span><img th:src="@{/images/ticon.png}" /></span>
      <div class="tipright">
        <p></p>
        <cite>如果是请点击确定按钮 ，否则请点取消。</cite> </div>
    </div>
    <input type="hidden" id="did2"   />
    <div class="tipbtn">
      <input name="" type="button"  class="sure" value="确定" onclick="yes()" />
      &nbsp;
      <input name="" type="button"  class="cancel" value="取消" onclick="tipClose()" />
    </div>
  </div>
</div>
<script type="text/javascript">
	$('.tablelist tbody tr:odd').addClass('odd');
</script>
</body>
</html>
